<div class="container-fluid">
    <div ng-controller="templateStrategyCreateController">
    <div class="row">
        <div class="col-sm-12 condensed-list">
            <form name="templateStrategyCreateForm" class="form-inline" role="form" novalidate>
                <ul class="list-group">
                    <li class="list-group-item">
                        <i class="glyphicon glyphicon-plus" ng-class="createRequest.children.length ? (createRequest.$closed ? 'glyphicon-plus' : 'glyphicon-minus') : 'glyphicon-leaf'" ng-click="createRequest.$closed =!createRequest.$closed;"></i>
                        <label>生成策略</label>
                        <div class="input-group" style="margin-right: 4px;">
                            <span class="input-group-addon" ng-class="{'text-danger': templateStrategyCreateForm.name.$error.required}">name</span>
                            <input name="name" uib-tooltip="{{getMessage('name',templateStrategyCreateForm.name.$error,tagRules.TemplateStrategy.attributes)}}"
                                   tooltip-trigger="none" tooltip-is-open="templateStrategyCreateForm.name.$invalid && templateStrategyCreateForm.name.$dirty"
                                   ng-model="createRequest.name" type="text" class="form-control input-sm" placeholder="名称" ng-maxlength="tagRules.TemplateStrategy.attributes.name.maxlength.rule" ng-required="tagRules.TemplateStrategy.attributes.name.required.rule"/>
                        </div>
                        <div class="btn-group">
                            <button type="button" class="btn btn-sm btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <span class="glyphicon glyphicon-plus"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <li ng-repeat="tagName in tagRules.TemplateStrategy.children"><a href="javascript:void(0);" ng-click="add(tagName,createRequest)">{{tagName}}</a></li>
                            </ul>
                        </div>
                        <ul ui-sortable="sortableOptions" ng-model="createRequest.children" ng-init="parent=createRequest;" ng-include="'recursion'" class="list-group" ng-show="!createRequest.$closed && createRequest.children.length"></ul>
                    </li>
                </ul>
            </form>
            <br/>
            <form class="form-horizontal" role="form" novalidate>
                <div class="form-group">
                    <div class="col-sm-3 col-sm-offset-5">
                        <button type="button" class="btn btn-warning btn-sm" location-back="/business/templateStrategy/manage/{{createRequest.generatorId}}">取消</button>
                        <button type="button" ng-disabled="templateStrategyCreateForm.$invalid || templateStrategyCreateForm.$pristine" class="btn btn-primary btn-sm" ng-click="create()">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</div>
<script id="recursion" type="text/ng-template">
    <li class="list-group-item" ng-repeat="child in parent.children" ng-init="p=parent;child.__hashKey = hashKey(child)">
        <i class="glyphicon glyphicon-plus" ng-class="child.children.length ? (child.$closed ? 'glyphicon-plus' : 'glyphicon-minus') : 'glyphicon-leaf'" ng-click="child.$closed =! child.$closed;"></i>
        <label>{{child.tagName}}</label>
        <div class="input-group" ng-repeat="(name,attribute) in tagRules[child.tagName].attributes" ng-switch="name" style="margin-right: 4px;">
            <span class="input-group-addon" ng-class="{'text-danger':attribute.required.rule && templateStrategyCreateForm[name + child.__hashKey].$error.required}">{{name}}</span>
            <select ng-switch-when="template" uib-tooltip="{{getMessage(name,templateStrategyCreateForm[name + child.__hashKey].$error,tagRules[child.tagName].attributes)}}"
                    tooltip-trigger="none" tooltip-is-open="templateStrategyCreateForm[name + child.__hashKey].$invalid && templateStrategyCreateForm[name + child.__hashKey].$dirty"
                    name="{{name + child.__hashKey}}" ng-model="child[name]" ng-options="template.id as template.name for template in templates" class="form-control input-sm" ng-required="attribute.required.rule">
                <option value="">--选择模板--</option>
            </select>
            <input ng-switch-default uib-tooltip="{{getMessage(name,templateStrategyCreateForm[name + child.__hashKey].$error,tagRules[child.tagName].attributes)}}"
                   tooltip-trigger="none" tooltip-is-open="templateStrategyCreateForm[name + child.__hashKey].$invalid && templateStrategyCreateForm[name + child.__hashKey].$dirty"
                   name="{{name + child.__hashKey}}" type="text" ng-model="child[name]" size="{{attribute.size}}" placeholder="{{attribute.placeholder}}" class="form-control input-sm" ng-required="attribute.required.rule"/>
        </div>
        <div class="btn-group">
            <button type="button" class="btn btn-danger btn-sm" ng-click="delete(child,p);"><span class="glyphicon glyphicon-remove"></span></button>
            <button ng-disabled="copyNode==child" type="button" class="btn btn-success btn-sm" ng-click="copy(child);"><span class="glyphicon glyphicon-copy"></span></button>
            <button ng-if="tagRules[child.tagName].children.length" ng-disabled="!canCopy(child)" type="button" class="btn btn-success btn-sm" ng-click="paste(child);"><span class="glyphicon glyphicon-paste"></span></button>
            <button ng-if="tagRules[child.tagName].children.length" type="button" class="btn btn-success dropdown-toggle btn-sm" data-toggle="dropdown">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
            </button>
            <ul ng-if="tagRules[child.tagName].children.length" class="dropdown-menu dropdown-menu-right" role="menu">
                <li ng-repeat="tagName in tagRules[child.tagName].children"><a href="javascript:void(0);" ng-click="add(tagName,child)">{{tagName}}</a></li>
            </ul>
        </div>
        <ul ui-sortable="sortableOptions" ng-model="child.children" class="list-group" ng-include="'recursion'" ng-show="!child.$closed && child.children.length" ng-init="parent=child;"></ul>
    </li>
</script>